package com.robb19y.rgbdscanner.core;

import java.io.Serializable;

/**
 * RGBDData contains the color (RGB) and depth data of one pixel. 
 * @author robb19y
 *
 */
public class RGBDData implements Serializable{
	private static final long serialVersionUID = 1L;
	private double[] color;
	private double[] position;
	private double[] projective;
	
	
	/**
	 * Construct and instance of RGBDData
	 * @param color pixel color
	 * @param projective pixel projective <x,y,d>
	 * @param camera depth camera.
	 */
	public RGBDData(double[] color, double[] projective) {
		super();
		this.color = color;
		
		this.projective = projective;
	}

	/**
	 * Returns the color of the pixel.
	 * @return the color of the pixel.
	 */
	public double[] getColor() {
		return color;
	}

	/**
	 * Returns the position <X,Y,Z> in camera frame of the pixel. (Leazy loading).
	 * @return the position in camera frame of the pixel.
	 */
	public double[] getPosition() {
		return position;
		/*if(position == null){
			//position = camera.convertToRealWorld(projective);
			convert();
			return position;
		}else{
			return position;
		}*/
				
	}

	/**
	 * Returns the projective <x,y,z> of the pixel.
	 * @return the projective <x,y,z> of the pixel.
	 */
	public double[] getProjective() {
		return projective;
	}
	
	/**
	 * Returns the depth value of the pixel.
	 * @return the depth value of the pixel.
	 */
	public double getDepth(){
		return projective[2];
	}
	
	/**
	 * Returns the red value of the pixel.
	 * @return the red value of the pixel.
	 */
	public double getRed(){
		return color[0];
	}
	
	/**
	 * Returns the green value of the pixel.
	 * @return the green value of the pixel.
	 */
	public double getGreen(){
		return color[1];
	}
	
	/**
	 * Returns the blue value of the pixel.
	 * @return the blue value of the pixel.
	 */
	public double getBlue(){
		return color[2];
	}
	
	/**
	 * Define if the pixel acquisition is valid.
	 * @return true if the pixel acquisition is valid, false otherwise. 
	 */
	public boolean isValid(){
		return projective[2] > 0;		
	}
	
	public void setPosition(double[] position){
		this.position = position;
	}
	
	public void convert(double xres,double yres){
		position = new double[3];
		 position[0] = (projective[2]*(projective[0]-xres*0.5)/586)/1000;
		 position[1] = (projective[2]*(projective[1]-yres*0.5)/586)/1000;
		 position[2] = projective[2]/1000;
	}

}
